package com.utility.md5;

import org.apache.commons.codec.digest.DigestUtils;

/**
 * MD5签名工具类
 * @author 林建波
 */
public class MD5Utility {
	/**
	 * 将字符串转换为十六进制字符串
	 */
	public static String encodeToUpperCase(String source){
		if(source == null || source.trim().length() == 0){
			return "";
		}
		try{
			return DigestUtils.md5Hex(source).toUpperCase();
		}catch(Exception e){
			throw new RuntimeException(e);
		}
	}
	
	/**
	 * 将字符串转换为十六进制字符串
	 */
	public static String encodeToLowerCase(String source){
		if(source == null || source.trim().length() == 0){
			return "";
		}
		try{
			return DigestUtils.md5Hex(source).toLowerCase();
		}catch(Exception e){
			throw new RuntimeException(e);
		}
	}
	
	public static void main(String[] args) {
		System.out.println(encodeToUpperCase("abc"));
		System.out.println(encodeToLowerCase("abc"));
	}
}
